
var webpack = require("webpack");
var path = require("path");

// 将require css文件提取到header中
var ExtractTextPlugin = require('extract-text-webpack-plugin');

var SpritesmithPlugin = require('webpack-spritesmith');

var config = {
    context: __dirname,
    entry: {
        index: ['./src/index.js'],
    },
    output: {
        path: path.join(__dirname, "dist"),
        publicPath: "dist/", // relative path for github pages
        filename: "[name].js", // no hash in main.js because index.html is a static page
        chunkFilename: 'chunk/[name].[chunkhash:5].js',
    },
    // recordsOutputPath: path.join(__dirname, "records.json"),
    module: {
        loaders: [{
            test: /\.js?$/,
            exclude: /(node_modules|bower_components)/,
            loader: 'babel', // 'babel-loader' is also a legal name to reference
            query: {
              presets: ['react', 'es2015', "stage-2", "stage-3"],
            }
        }, {
            test: /\.scss$/,
            loader: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader')
        }]
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env': {
          'NODE_ENV': '"production"'
        },
        // $: 'jquery',
        // jQuery: 'jquery'
      }),
      new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 20 }),
      new webpack.optimize.OccurenceOrderPlugin(),
      new webpack.HotModuleReplacementPlugin(),
      new ExtractTextPlugin("css/[name].[contenthash:5].css", {
          disable: false,
          allChunks: true
      }),
      new webpack.NoErrorsPlugin(),
      new SpritesmithPlugin({
        src: {
          cwd: path.resolve(__dirname, 'src/imgs/sprites'),
          glob: '*.png'
        },
        target: {
          image: path.resolve(__dirname, 'dist/imgs/sprites.png'),
          css: path.resolve(__dirname, 'src/sass/sprite.scss')
        },
        apiOptions: {
          cssImageRef: publicPath + "imgs/sprites.png"
        }
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      }),
    ],
    fakeUpdateVersion: 0
};


module.exports = config;
